﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class User_ListOwnCourse : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        String userid = "";
        if (Session["UserID"] != null)
        {
            userid = (String)Session["UserID"];
        }
        //DataSourceSelectArguments sc = new DataSourceSelectArguments();
        SqlDataSource1.SelectCommand = "SELECT * FROM courses, register_list, users WHERE register_list.course_id = courses.id AND users.id = register_list.user_id AND users.id='" + userid  + "'";
        //DataView dv = (DataView)SqlDataSource1.Select(sc);

        //if(dv.Count != 0)
        {

        }
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "UnSelect")
        {
            String courseID = ((HiddenField)e.Item.FindControl("hiddenID")).Value;
            String userid = (String)Session["UserID"];
            String date = DateTime.Now.ToString();
            String query = "DELETE FROM register_list WHERE user_id='" + userid + "' AND course_id='" + courseID + "'";
            SqlDataSource2.DeleteCommand = query;
            SqlDataSource2.Delete();

            Response.Redirect(Request.RawUrl);
        }
    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        
    }
}